﻿using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Collections;
using System.Collections.Generic;
using ISolutions.SharePoint.Mui.Impl.Resources;
using ISolutions.SharePoint.Mui.Helper;

namespace ISolutions.SharePoint.Mui.Layouts.ISolutions.SharePoint.Mui
{
    public partial class MuiManager : LayoutsPageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.CreateColumns();
                this.FillGrid();
            }
        }

        private void CreateColumns()
        {
            foreach (MuiLanguage language in MuiService.Instance.GetLanguages(SPContext.Current.Web))
            {
                SPBoundField field = new SPBoundField();
                field.HeaderText = language.DisplayName;
                field.DataField = String.Format("Res{0}", language.LanguageCode);
                gridResources.Columns.Add(field);
            }
        }

        private void FillGrid()
        {           
            this.gridResources.DataSource = GetResources();
            this.gridResources.DataBind();
        }

        private IEnumerable<MuiResource> GetResources()
        {
            IList<MuiResource> resources = new List<MuiResource>();
            SPUserResourceCollection resCol = SPContext.Current.Web.UserResources;

            foreach (SPUserResource res in resCol)
            {
                resources.Add(MuiResourceService.GetMuiResource(res));
            }

            return resources;
        }
    }

    internal class UserResource
    {

    }
}
